/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.eventos.bc;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.cip.esymons.eventos.be.MaterialAcademico;

/**
 *
 * @author Lizardo Rios
 */
@Stateless
public class MaterialAcademicoFacade implements MaterialAcademicoFacadeLocal {
    @PersistenceContext
    private EntityManager em;

    public void create(MaterialAcademico material) {
        em.persist(material);
    }

    public void edit(MaterialAcademico material) {
        em.merge(material);
    }

    public void remove(MaterialAcademico material) {
        em.remove(em.merge(material));
    }

    public MaterialAcademico find(Object id) {
        return em.find(MaterialAcademico.class, id);
    }

    public List<MaterialAcademico> findAll() {
        return em.createQuery("select m from MaterialAcademico m ").getResultList();
    }

    public List<MaterialAcademico> listarMaterialesXCurso(Integer codigoCurso) {
        return em.createQuery("select m from MaterialAcademico m where m.curCodigo.eveCodigo = ?1")
                .setParameter(1, codigoCurso)
                .getResultList();
    }

    public MaterialAcademico buscarUltimoCodigo() {
        return (MaterialAcademico) em.createQuery("select m from MaterialAcademico m where m.macCodigo in (select max(ma.macCodigo) from MaterialAcademico ma)")
                .getSingleResult();
    }
    
}

